from django.db import models
from datetime import datetime

class UserProfile(models.Model):
    """
    用户表
    """
    GENDEN_CHOICES = (
        ("male",u'男'),
        ("female",u"女")
    )

    STATE_CHOICES = (
        (1,u"正常"),
        (0,u"封号")
    )

    mobile = models.CharField(max_length=11, verbose_name="手机号码")
    password = models.CharField(max_length=50, verbose_name="密码")
    name = models.CharField(max_length=30,blank=True,verbose_name="用户名")
    avatar = models.ImageField(upload_to='users/avatar/',null=True,blank=True,verbose_name="用户头像")
    gender = models.CharField(max_length=6,choices=GENDEN_CHOICES,default="male",null=True,verbose_name="性别")
    email =  models.EmailField(max_length=30,null=True,blank=True,verbose_name="邮箱")
    state = models.IntegerField(choices=STATE_CHOICES,default=1,null=True,verbose_name="账号状态")
    token = models.CharField(max_length=100,null=True,blank=True,verbose_name="Token")
    time_out = models.DateTimeField(null=True,blank=True,verbose_name="token过期时间")
    add_time = models.DateTimeField(default=datetime.now,verbose_name="注册时间")

    class Meta:
        verbose_name = "用户信息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name

class VerifyCode(models.Model):
    """
    短信验证码，回填验证码进行验证，可以保存在redis中
    """
    code = models.CharField(max_length=10,verbose_name="验证码")
    mobile = models.CharField(max_length=11,verbose_name="手机号码")
    add_time = models.DateTimeField(default=datetime.now,verbose_name="添加时间")


    class Meta:
        verbose_name = "注册验证码"
        verbose_name_plural = verbose_name


    def __str__(self):
         return self.code
